package com.gxa.scdx.cloud.user.service.impl;

import com.gxa.scdx.cloud.user.pojo.Device;
import com.gxa.scdx.cloud.user.mapper.DeviceMapper;
import com.gxa.scdx.cloud.user.service.DeviceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 设备表服务实现类
 *
 * @author 颜可翔
 */

@Service("deviceService")
public class DeviceServieImpl implements DeviceService {
    @Resource
    private DeviceMapper deviceMapper;


    public Map<String, Object> selectByUserId(int userId){

        Map<String, Object> map = new HashMap<>();

        map.put("code", 200);
        map.put("msg", "查询成功");
        map.put("data", this.deviceMapper.selectByUserId(userId));
        return map;
    }


    public Map<String, Object> selectAll(){
        Map<String, Object> map = new HashMap<>();

        map.put("code", 200);
        map.put("msg", "查询成功");
        map.put("data", this.deviceMapper.selectAll());
        return map;
    }

    public Map<String, Object> insert(Device device){
        this.deviceMapper.insert(device);

        Map<String, Object> map = new HashMap<>();

        map.put("code", 200);
        map.put("msg", "插入成功");

        return map;
    }

    public  Map<String, Object> selectById(String id){
        int count  = this.deviceMapper.selectById(id);

        Map<String, Object> map = new HashMap<>();
        if (count == 1){
            map.put("code", 200);
            map.put("msg", "已注册");
        }else {
            map.put("code", 201);
            map.put("msg", "未注册");
        }
        return map;
    }

    public  Map<String, Object> count (){
        Map<String, Object> map = new HashMap<>();

        int count  = this.deviceMapper.count();

        map.put("code", 200);
        map.put("msg", "success");
        map.put("data",count);

        return map;
    }


}
